package com.niuke;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 26. boss的收入
 * https://blog.csdn.net/qfc_128220/article/details/128052725
 */
public class NiukeMoni26 {

    public static Map<Integer, Integer[]> data = new HashMap<>();
    public static Map<Integer, Integer> result = new HashMap<>();
    ;

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int num = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < num; i++) {
            String[] item = scanner.nextLine().split(" ");
            Integer key = Integer.parseInt(item[0]);
            Integer[] value = new Integer[2];
            value[0] = Integer.parseInt(item[1]);
            value[1] = Integer.parseInt(item[2]);
            data.put(key, value);
        }

        for (Integer key : data.keySet()) {
            dfs(key);
        }

        for (Integer key : result.keySet()) {
            System.out.println(key + " " + result.get(key));
        }

    }

    public static void dfs(Integer key) {
        Integer[] item = data.get(key);
        if (data.containsKey(item[0])) {
            Integer[] next = data.get(item[0]);
            next[1] = next[1] + item[1] / 100 * 15;
            data.put(item[0], next);
            item[1] = item[1] - item[1] / 100 * 100;
            data.put(key, item);

            dfs(item[0]);
        } else {
            result.put(item[0], result.getOrDefault(item[0], 0) + item[1] / 100 * 15);
            item[1] = item[1] - item[1] / 100 * 100;
            data.put(key, item);
        }
    }

}
